package com.zeh.service.Impl;

import com.zeh.mapper.TypeMapper;
import com.zeh.pojo.Type;
import com.zeh.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TypeServiceImpl implements TypeService {

    @Autowired
    private TypeMapper typeMapper;

    @Transactional //是声明式事务管理 编程中使用的注解
    @Override
    public int saveType(Type type) {
       return  typeMapper.insert(type);
    }

    @Transactional
    @Override
    public Type getType(Long id) {
       return typeMapper.selectById(id);
    }

    @Transactional
    @Override
    public List<Type> getAllType() {
       return typeMapper.selectList(null);
    }

    @Transactional
    @Override
    public Type getTypeName(String name) {
        return typeMapper.getTypeByName(name);
    }

    @Transactional
    @Override
    public int update(Type type) {
        return typeMapper.updateType(type);
    }

    @Transactional
    @Override
    public void deleteType(Long id) {
       typeMapper.deleteById(id);
    }

    @Transactional
    @Override
    public List<Type> getAllTypeAndBlog(){
        return typeMapper.getAllTypeAndBlog();
    }


}
